<template>
  <div class="pubg-banner">
    <!-- 装饰元素 -->
    <div class="banner-decoration decoration-1"></div>
    <div class="banner-decoration decoration-2"></div>
    
    <div class="container">
      <div class="banner-carousel" ref="carouselRef">
        <div 
          v-for="(banner, index) in banners" 
          :key="index"
          class="carousel-item"
          :class="{
            active: index === currentIndex,
            prev: index === (currentIndex - 1 + banners.length) % banners.length
          }"
        >
          <div class="banner-content">
            <h2>{{ banner.title }}</h2>
            <p>{{ banner.description }}</p>
            <button class="banner-btn">查看详情</button>
          </div>
          <div class="banner-image">
            <img :src="banner.imageUrl" :alt="banner.title" />
          </div>
        </div>
        
        <div class="carousel-indicators">
          <button 
            v-for="(banner, index) in banners" 
            :key="index"
            class="indicator" 
            :class="{ active: index === currentIndex }"
            @click="goToSlide(index)"
            :aria-label="`转到幻灯片 ${index + 1}`"
          ></button>
        </div>
        
        <button class="carousel-control prev" @click="prevSlide" aria-label="上一张">
          <span>‹</span>
        </button>
        <button class="carousel-control next" @click="nextSlide" aria-label="下一张">
          <span>›</span>
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'

const carouselRef = ref(null)
const currentIndex = ref(0)
const banners = ref([
  {
    title: "全新赛季开启，掌握这些技巧轻松上分",
    description: "赛季更新，新地图、新武器、新机制全面解析，助你快速适应新版本！",
    imageUrl: "/src/assets/pubg-images/pubg-main-banner.svg"
  },
  {
    title: "和平精英2024全球总决赛前瞻",
    description: "各大赛区顶尖战队分析，赛事规则详解，观赛指南全攻略！",
    imageUrl: "/src/assets/pubg-images/pubg-tournament-banner.svg"
  },
  {
    title: "海岛地图资源点全面解析",
    description: "热门落地点、隐藏资源、战术路线，成为海岛地图的王者！",
    imageUrl: "/src/assets/pubg-images/pubg-map-banner.svg"
  }
])

let intervalId = null

const startAutoPlay = () => {
  intervalId = setInterval(() => {
    nextSlide()
  }, 5000)
}

const stopAutoPlay = () => {
  if (intervalId) {
    clearInterval(intervalId)
    intervalId = null
  }
}

const nextSlide = () => {
  currentIndex.value = (currentIndex.value + 1) % banners.value.length
}

const prevSlide = () => {
  currentIndex.value = (currentIndex.value - 1 + banners.value.length) % banners.value.length
}

const goToSlide = (index) => {
  currentIndex.value = index
}

onMounted(() => {
  startAutoPlay()
  
  // 鼠标悬停时停止自动播放
  if (carouselRef.value) {
    carouselRef.value.addEventListener('mouseenter', stopAutoPlay)
    carouselRef.value.addEventListener('mouseleave', startAutoPlay)
  }
})

onUnmounted(() => {
  stopAutoPlay()
  
  if (carouselRef.value) {
    carouselRef.value.removeEventListener('mouseenter', stopAutoPlay)
    carouselRef.value.removeEventListener('mouseleave', startAutoPlay)
  }
})
</script>

<style scoped>
/* 全局动画 */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(100px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.pubg-banner {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  padding: 3rem 0;
  position: relative;
  overflow: hidden;
}

/* 背景装饰效果 */
.pubg-banner::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 20% 30%, rgba(240, 103, 62, 0.1) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(233, 69, 96, 0.1) 0%, transparent 40%);
  z-index: 0;
}

.pubg-banner::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: 
    linear-gradient(45deg, rgba(0, 0, 0, 0.1) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0, 0, 0, 0.1) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(0, 0, 0, 0.1) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(0, 0, 0, 0.1) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  z-index: 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  position: relative;
  z-index: 1;
}

.banner-carousel {
  width: 100%;
  height: 450px;
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4);
  background: linear-gradient(135deg, var(--color-pubg-secondary), #1a1a1a);
}

.carousel-item {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.carousel-item.active {
  opacity: 1;
  transform: translateX(0);
  z-index: 10;
}

.carousel-item.prev {
  opacity: 0.8;
  transform: translateX(-100%);
}

.banner-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3rem;
  color: white;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0.5), transparent);
  z-index: 10;
  animation: slideInRight 0.8s ease-out;
}

.banner-content h2 {
  font-size: 2.5rem;
  margin: 0 0 1.5rem 0;
  font-weight: 800;
  line-height: 1.1;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  position: relative;
  display: inline-block;
}

.banner-content h2::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 0;
  width: 80px;
  height: 4px;
  background: linear-gradient(90deg, var(--color-pubg-primary), transparent);
  border-radius: 2px;
}

.banner-content p {
  font-size: 1.2rem;
  margin: 0 0 2rem 0;
  opacity: 0.95;
  line-height: 1.6;
  max-width: 500px;
}

.banner-btn {
  align-self: flex-start;
  padding: 0.9rem 2rem;
  background: linear-gradient(135deg, var(--color-pubg-primary), var(--color-pubg-primary-dark));
  color: white;
  border: none;
  border-radius: 30px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 6px 20px rgba(240, 103, 62, 0.4);
  position: relative;
  overflow: hidden;
  z-index: 1;
}

.banner-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s;
  z-index: 0;
}

.banner-btn:hover::before {
  left: 100%;
}

.banner-btn:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 10px 25px rgba(240, 103, 62, 0.6);
}

.banner-btn:active {
  transform: translateY(0);
}

.banner-image {
  flex: 1.5;
  background-size: cover;
  background-position: center;
  position: relative;
  overflow: hidden;
}

.banner-image::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.3));
}

/* 图片悬浮效果 */
.banner-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.carousel-item:hover .banner-image img {
  transform: scale(1.05);
}

.carousel-indicators {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 20;
}

.indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.indicator::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.8), transparent);
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}

.indicator:hover {
  background-color: rgba(255, 255, 255, 0.8);
  transform: scale(1.3);
}

.indicator:hover::before {
  transform: translateX(100%);
}

.indicator.active {
  background-color: var(--color-pubg-primary);
  transform: scale(1.3);
  box-shadow: 0 0 15px rgba(240, 103, 62, 0.6);
}

.carousel-control {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 50px;
  height: 50px;
  background-color: rgba(0, 0, 0, 0.6);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 1.8rem;
  cursor: pointer;
  z-index: 20;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(5px);
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.carousel-control:hover {
  background-color: var(--color-pubg-primary);
  transform: translateY(-50%) scale(1.1);
  border-color: white;
  box-shadow: 0 0 20px rgba(240, 103, 62, 0.7);
}

.carousel-control.prev {
  left: 20px;
}

.carousel-control.next {
  right: 20px;
}

/* 装饰元素 */
.banner-decoration {
  position: absolute;
  z-index: 5;
}

.decoration-1 {
  top: -50px;
  right: -50px;
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, rgba(240, 103, 62, 0.2) 0%, transparent 70%);
  border-radius: 50%;
  animation: float 8s ease-in-out infinite;
}

.decoration-2 {
  bottom: -80px;
  left: -80px;
  width: 250px;
  height: 250px;
  background: radial-gradient(circle, rgba(233, 69, 96, 0.2) 0%, transparent 70%);
  border-radius: 50%;
  animation: float 10s ease-in-out infinite reverse;
}

/* 响应式设计 */
@media (max-width: 992px) {
  .banner-carousel {
    height: 400px;
  }
  
  .banner-content {
    padding: 2.5rem;
  }
  
  .banner-content h2 {
    font-size: 2.2rem;
  }
  
  .banner-content p {
    font-size: 1.1rem;
  }
}

@media (max-width: 768px) {
  .pubg-banner {
    padding: 2rem 0;
  }
  
  .banner-carousel {
    height: 500px;
  }
  
  .carousel-item {
    flex-direction: column;
  }
  
  .banner-content {
    flex: 1.5;
    padding: 2rem;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.7));
  }
  
  .banner-content h2 {
    font-size: 2rem;
  }
  
  .banner-content p {
    font-size: 1rem;
  }
  
  .banner-image {
    flex: 1;
  }
  
  .carousel-control {
    width: 45px;
    height: 45px;
    font-size: 1.5rem;
  }
  
  .carousel-control.prev {
    left: 15px;
  }
  
  .carousel-control.next {
    right: 15px;
  }
}

@media (max-width: 480px) {
  .pubg-banner {
    padding: 1.5rem 0;
  }
  
  .banner-carousel {
    height: 450px;
    border-radius: 12px;
  }
  
  .banner-content {
    padding: 1.5rem;
  }
  
  .banner-content h2 {
    font-size: 1.8rem;
  }
  
  .banner-content p {
    font-size: 0.95rem;
  }
  
  .banner-btn {
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
  }
  
  .carousel-indicators {
    bottom: 20px;
    gap: 10px;
  }
  
  .indicator {
    width: 10px;
    height: 10px;
  }
}
</style>